package com.leyu.mall.service.mdm.impl;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.leyu.mall.dao.mdm.MDMCityMapper;
import com.leyu.mall.domain.mdm.MDMCity;
import com.leyu.mall.service.mdm.IMDMCityService;
@Service
@Transactional(rollbackFor=Exception.class)

public class MDMCityServiceImpl implements IMDMCityService{
	
	 

	@Resource
	private MDMCityMapper mdmCityMapper;
	
	
	
	public List<MDMCity> getMDMCityList()throws Exception{
		return this.mdmCityMapper.getAllMDMCity();
	}
	

	public Map<String,List> getMDMCityMap()throws Exception{
		List<MDMCity>  allList =  this.mdmCityMapper.getAllMDMCity();
		Map resultMap = new HashMap();
		
		for(MDMCity mc : allList ){
			if(!resultMap.containsKey(mc.getProvinceName())){
			List newList = new ArrayList();
			newList.add(mc);
			resultMap.put(mc.getProvinceName(), newList);
			}else {
				List oldlist = (List)resultMap.get(mc.getProvinceName());
				oldlist.add(mc);
				resultMap.put(mc.getProvinceName(), oldlist);
			}
		 
		}
		return resultMap;
	}
	
	public List<MDMCity> getAllHotMDMCity()throws Exception{
		return this.mdmCityMapper.getAllHotMDMCity();
	}
	
	public  void  addMDMCity(MDMCity record)throws Exception{
		  this.mdmCityMapper.insert(record);
	}
	public void  deleteMDMCity(Long cityId)throws Exception{
		  this.mdmCityMapper.deleteByPrimaryKey(cityId);
	}
	public void  updateMDMCity(MDMCity record)throws Exception{
		  this.mdmCityMapper.updateByPrimaryKey(record);
	}
	public MDMCity getMDMCityeById(Long cityId)throws Exception{
		return this.mdmCityMapper.getMDMCityeById(cityId);
	}
}